using System;
using System.Linq;
using CommandSystem;

namespace RgCore.CustomSide.Commands.SideManagerCommands
{
    public class List : ICommand
    {
        public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
        {
            if (!sender.CheckPermission(PlayerPermissions.ForceclassWithoutRestrictions))
            {
                response = $"权限不足,需要{nameof(PlayerPermissions.ForceclassWithoutRestrictions)}权限";
                return false;
            }

            response = "以下是目前所有注册的阵营：";
            foreach (var side in SideManager.Sides)
            {
                response +=
                    $"\n[{side.Id}]（<color={side.SideColor}>{side.SideName}</color>）友伤：<color={(side.FriendlyFire ? "#FF9999" : "#00FF00")}>{side.FriendlyFire}</color>";
                if (side.FriendlySideIds.Any())
                {
                    response += " | 友好：";
                    foreach (var sideid in side.FriendlySideIds)
                    {
                        CustomSide cs = sideid.GetSideById();
                        if (cs == null)
                            continue;
                        response += $" <color={cs.SideColor}>{cs.SideName}</color>";
                    }
                }
            }

            response += "\n----------------";
            return true;
        }

        public string Command { get; } = "list";
        public string[] Aliases { get; } = Array.Empty<string>();
        public string Description { get; } = "获取全部注册的阵营";
    }
}